//
//  FileResume.swift
//  Trans
//
//  Created by zcj on 2024/12/18.
//  description: listener接受到这个就是req，之后要回一个ans的，而client收到resume就是ans，然后开始借用FileData协议开始发送信息

import Foundation
class FileResume:BaseData{
    var fileId:FileId = 0
    var size:FSIZE = 0
    var type:INT32 = 0 //1代表为回应类型的 0代表请求类型的
    var msg:String = ""//如果有信息就代表有问题，应该提醒
    
    init(fileId:FileId,type:Int32 = 0,msg:String = "") {
        self.fileId = fileId
        self.msg = msg
        self.type = type
        super.init()
    }
    
    
    enum CodingKeys: String, CodingKey{
        case fileId
        case size
        case msg
        case type
    }
    
    required init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy:CodingKeys.self)
        fileId = try container.decode(FileId.self, forKey: .fileId)
        size = try container.decode(FSIZE.self, forKey: .size)
        msg = try container.decode(String.self, forKey: .msg)
        type = try container.decode(INT32.self, forKey: .type)
        try super.init(from: decoder)
    }
    
    override func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(fileId, forKey: .fileId)
        try container.encode(size, forKey: .size)
        try container.encode(msg, forKey: .msg)
        try container.encode(type, forKey: .type)
        try super.encode(to: encoder)
    }
    
    override func getType() -> UINT32 {
        return FILE_RESUME;
    }
}
